export const scopeInit = {
  data() {
    return {
      scopeQuery: {},
      scopePage: { //分页控制
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      scopeData: [],
      scopeAllData:[],
      scopeSelectionList: []
    }
  },
  computed: {
    scopeIds() { //所有勾选的id
      let ids = [];
      this.scopeSelectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    scopeSearchReset() { //清空触发
      this.scopeQuery = {};
      let inputs=this.getByClass(document,'el-input__inner');
      inputs.forEach((input,index)=>{
        if(index==0) return;
        input.value='';
      });

      if(this.searchScopeForm){
        Object.keys(this.searchScopeForm).forEach(key =>  this.searchScopeForm[key]= '');
      }
      this.scopeSearhFn(this.scopePage);
    },
    scopeSearchChange(params) { //搜索触发
      params=Object.assign(params,this.searchForm);
      this.scopeSearhFn(this.scopePage,params);
    },
    scopeSelectionChange(list) { //勾选项发生变化触发
      this.scopeSelectionList = list;
    },
    scopeCurrentChange(currentPage) { //切换分页时触发该事件
      this.scopePage.currentPage = currentPage;
      this.scopeSearhFn(this.scopePage, this.scopeQuery);
    },
    scopeSizeChange(pageSize) { //切换分页每页显示的条数触发该事件
      this.scopePage.pageSize = pageSize;
      this.scopeSearhFn(this.scopePage, this.scopeQuery);
    },
    scopeRefreshChange() { //刷新
      if(this.scopeSearchForm){//如果有自定义搜索条件
          Object.assign(this.scopeQuery,this.scopeSearchForm);
      }
      this.scopeSearhFn(this.scopePage, this.scopeQuery);
    },
    scopeSearhFn(page,params={}){
       const { pageSize , currentPage } =page;
       this.scopeData=this.scopeAllData.slice(pageSize*(currentPage-1),pageSize*(currentPage-1)+pageSize).filter((param)=>{
                  var isfle=0;
                  var isall=0;
                  for(let i in params){
                     if(param[i].indexOf(params[i])>-1){
                       isfle++
                     }
                     isall++
                  }
                  if(isall===0){ //如果没有搜索条件不判断
                    return true
                  }else{//如果有搜索条件加判断
                    return isfle===isall
                  }

       })
    }
  }

}
